package com.own.component.common.login.util;

import com.own.component.common.exception.BusinessException;

import java.util.function.Supplier;

/**
 * BaseUtil
 *
 * @author chenxueli
 * @date 2022-08-17 14:52:00
 */
public class BaseUtil {

    /**
     * 缓存信息
     *
     * @param defaultUser 默认的用户信息
     * @param getFunction 获取方法
     * @param <T>         类型
     * @return 用户信息
     */
    public static <T> T get(T defaultUser, Supplier<T> getFunction) {
        var user = getFunction.get();
        var resultUser = user == null ? defaultUser : user;
        if (resultUser == null) {
            throw new BusinessException("没有获取到对应的登录信息");
        }
        return resultUser;
    }

}
